package com.itheima.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import com.itheima.bean.Student;
import com.itheima.service.StudentService;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Currency;

//@WebServlet("/studentServlet")
//@Controller
@RequestMapping("/student")
//@ResponseBody
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 处理分页查询的请求
     * @throws ServletException
     * @throws IOException
     */
    @RequestMapping("/selectByPage")
    public PageInfo<Student> selectByPage(Integer currentPage,Integer pageSize)  {

               return studentService.selectByPage(currentPage, pageSize);


    }

    /**
      * 处理添加学生的请求
     * @throws ServletException
     * @throws IOException
     */
    @RequestMapping("/addStudent")
    public Integer addStudent(Student student)  {

        return studentService.addStudent(student);

    }

    /**
     * 处理修改学生的请求
     * @throws ServletException
     * @throws IOException
     */
    @RequestMapping("/updateStudent")
    public Integer updateStudent(Student student)  {

        return studentService.updateStudent(student);

    }

    /**
     * 处理删除学生的请求
     * @throws ServletException
     * @throws IOException
     */
    @RequestMapping("/deleteStudent")
    public Integer deleteStudent(String number) {

        return studentService.deleteStudent(number);

    }

}
